<?php
// no direct access

defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');


class SimplelistingViewListings extends JView
{

//    function __construct( $config = array())
//	{
//
// 	 global $context;
//	 $context = 'simplelisting.list.';
// 	 parent::__construct( $config );
//	}
    
    function display($tpl = null){
//        global $mainframe, $context;
        $model =& $this->getModel('listings', 'SimplelistingModel');
        $document = & JFactory::getDocument();
        $db  =& JFactory::getDBO();
        $uri =& JFactory::getURI();
        $user =&JFactory::getUser();
        $document->setTitle( JText::_('TITLE_MAIN') );
        JToolBarHelper::title(JText::_('TITLE_MAIN'). ' [ ' . JText::_( 'TITLE_MANAGER' ) . ' ]' , 'simplelisting.png' );
        JToolBarHelper::back( 'Control Panel', 'index.php?option=com_simplelisting' );
        JToolBarHelper::publishList();
        JToolBarHelper::unpublishList();
        JToolBarHelper::addNew();
        JToolBarHelper::editList();
        JToolBarHelper::deleteList();

        $application= JFactory::getApplication();
        $option = JRequest::getCmd( 'option').'-listings';


        $filter_state     = $application->getUserStateFromRequest( $option.'filter_state', 'filter_state', '', 'word' );
        $filter_order     = $application->getUserStateFromRequest( $option.'filter_order', 'filter_order', 'a.ordering', 'cmd' );
        $filter_order_Dir = $application->getUserStateFromRequest( $option.'filter_order_Dir',  'filter_order_Dir', '', 'word' );
        $search           = $application->getUserStateFromRequest( $option.'search', 'search', '', 'string' );
        $search           = JString::strtolower( $search );

                
        $lists['state']     = JHTML::_('grid.state', $filter_state);
        $lists['order']     = $filter_order;
        $lists['order_Dir'] = $filter_order_Dir;
        $lists['search']    = $search;
        $items              = & $this->get( 'Data');
        $total              = & $this->get( 'Total');
        $pagination         = & $this->get( 'Pagination' );

    
        $this->assignRef('user',		$user);
        $this->assignRef('lists',		$lists);
        $this->assignRef('items',		$items);
        $this->assignRef('pagination',	$pagination);
        $this->assignRef('request_url',	$uri->toString());
    
    
    parent::display();

    }
  
    function displayEdit($simplelistingId)
	{
		JToolBarHelper::title(JText::_('TITLE_MAIN'). ' [ ' . JText::_( 'TITLE_EDIT' ) . ' ]' );
                JRequest::setVar( 'hidemainmenu', 1);
		JToolBarHelper::apply();
                JToolBarHelper::save();
		JToolBarHelper::cancel();

		$model = $this->getModel('listings', 'SimplelistingModel');
		$simplelisting = $model->getSimplelistingLists($simplelistingId);
		$this->assignRef('simplelisting', $simplelisting);
		parent::display();

	}

    function displayAdd(){
		JToolBarHelper::title(JText::_('TITLE_MAIN'). ' [ ' . JText::_( 'TITLE_ADD' ) . ' ]' );
                JRequest::setVar( 'hidemainmenu', 1);
		JToolBarHelper::save();
		JToolBarHelper::cancel();
//                JToolBarHelper::apply();

		$model = $this->getModel('listings', 'SimplelistingModel');
		$simplelisting = $model->getNewSimplelisting($simplelistingId);
		$this->assignRef('simplelisting', $simplelisting);

		parent::display();
	}
    
   
}
?>